# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html
import pymysql
import scrapy


class ScrapysteamItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    name = scrapy.Field()
    appId = scrapy.Field()
    url = scrapy.Field()
    rank = scrapy.Field()
    type = scrapy.Field()
    pass


class GameDet(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    appId = scrapy.Field()
    name = scrapy.Field()
    developers = scrapy.Field()
    publishers = scrapy.Field()
    issueDate = scrapy.Field()
    price = scrapy.Field()
    appTag = scrapy.Field()
    numOfComments = scrapy.Field()
    review = scrapy.Field()
    favorableRate = scrapy.Field()


class Mysqldb():
    def __init__(self):
        self.db = pymysql.connect(host='localhost',
                                  user='root',
                                  password='ff123456',
                                  port=3306,
                                  db='steam')
        self.cursor = self.db.cursor()
        self.cursor.execute('select version()')
        data = self.cursor.fetchone()
        print('Database version:', data)

    def get_appId(self, tableName, beginIndex, endIndex):
        sql = 'SELECT appId FROM ' + tableName + ' WHERE sortRank BETWEEN ' + str(beginIndex) + ' AND ' + str(
            endIndex) + ' ORDER BY sortRank'
        # print(sql)
        self.cursor.execute(sql)
        results = self.cursor.fetchall()
        return results
